package com.example.hospitallogin.assembly;

import java.io.Serializable;
import java.util.List;

/**
 * @author qiancheng@cqxyy.net
 * @date 2022/9/28
 */
public class PageBaseResponse<T> extends BaseResponse<PageData<T>> implements Serializable {
    public PageBaseResponse() {
    }

    public static <T> PageBaseResponse<T> success(PageData<T> data) {
        PageBaseResponse<T> response = new PageBaseResponse();
        response.setCode(ResultCode.SUCCESS.getCode());
        response.setDescription(ResultCode.SUCCESS.getMassage());
        response.setData(data);
        return response;
    }

    public static <T> PageBaseResponse<T> success(List<T> data, int currentPage, int pageSize, int total) {
        PageBaseResponse<T> response = new PageBaseResponse();
        response.setCode(ResultCode.SUCCESS.getCode());
        response.setDescription(ResultCode.SUCCESS.getMassage());
        response.setData(PageData.of(data, pageSize, currentPage, total));
        return response;
    }

    public static PageBaseResponse fail(String code, String description) {
        PageBaseResponse result = new PageBaseResponse();
        result.setCode(Integer.parseInt(code));
        result.setDescription(description);
        return result;
    }
}
